//index.js
var app = getApp()  
Page({
  data: {
    //轮播图
    Faults: [{"name":"电视", "info":{"img":"../images/television.png"}},
      {"name": "空调", "info": { "img": "../images/freezer.png" }},
      {"name": "电脑", "info": { "img": "../images/computer.png" }},
      {"name": "冰箱", "info": { "img": "../images/fridge.png" }},
      {"name": "微波炉", "info": { "img": "../images/microwave.png" }},
      {"name": "油烟机", "info": { "img": "../images/hoods.png" }},
      {"name": "热水器", "info": { "img": "../images/heater.png" }},
      {"name": "洗碗机", "info": { "img": "../images/washer.png" }}],
    images: [
      { url: app.data.ull +'images/wxhome/banner1.jpg'},
      { url: app.data.ull +'images/wxhome/banner2.jpg'},
      { url: app.data.ull +'images/wxhome/banner3.jpg'}
    ],
    //企业文化
    types:[
      { url: app.data.ull +'images/wxhome/timea.jpg' },
      { url: app.data.ull +'images/wxhome/timeb.jpg' },
      { url: app.data.ull +'images/wxhome/timec.jpg' }
    ],
    //快速预约
     index_type:["电视","空调","电脑","冰箱","微波炉","油烟机","热水器","洗碗机"
     ],

    //公告栏
    text: '人人修，我们中间商考虑考虑再不赚差价。',
    marqueePace: 1,//滚动速度
    marqueeDistance: 0,//初始滚动距离
    marqueeDistance2: 0,
    marquee2copy_status: false,
    marquee2_margin: 50,
    size: 17,
    orientation: 'left',//滚动方向
    interval: 20, // 时间间隔
  },

  //通过接口获取openid传递后台
  onLoad: function () {
  },
  
    // 公告栏页面显示
  onShow: function () { 
    var vm = this;
    var length = vm.data.text.length * vm.data.size;//文字长度
    var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度
    vm.setData({
      length: length,
      windowWidth: windowWidth,
      marquee2_margin: length < windowWidth ? windowWidth - length :         vm.data.marquee2_margin//当文字长度小于屏幕长度时，需要增加补白
    });
    vm.run1();// 水平一行字滚动完了再按照原来的方向滚动

   
    
   },
   
  //公告栏滑动
  run1: function () {
    var vm = this;
    var interval = setInterval(function () {
      if (-vm.data.marqueeDistance < vm.data.length) {
        vm.setData({
          marqueeDistance: vm.data.marqueeDistance - vm.data.marqueePace,
        });
      } else {
        clearInterval(interval);
        vm.setData({
          marqueeDistance: vm.data.windowWidth
        });
        vm.run1();
      }
    }, vm.data.interval);
  },
  quickOrder: function(e) {
    var type = e.currentTarget.dataset.type;
    if(type) {
      app.data.typeSelected = type; 
      wx.switchTab({
        url: '../orderpages/orderpages',
        success: function(e) {
          var page = getCurrentPages().pop();
          if(page == undefined || page == null)
            return;
          page.onLoad();
        }
      })
    }
  }
})

